unit DatabaseConfiguration;

interface

uses
  System.SysUtils, System.Classes, Data.DB, Data.Win.ADODB;

type
  TDataModule1 = class(TDataModule)
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
  private
    function getSQLConnectionString(): string;
    function getSQLNativeClientConnectionString(): string;
  public
    constructor Create(AOwnet: TComponent); override;
    function getConnectionString(): string;
    function getConnection(): TADOConnection;
    function getQuery(): TADOQuery;
    procedure executeQuery(query: string);
  end;

var
  DataModule1: TDataModule1;
  dbConf: TDataModule1;

implementation

uses
  Project;

{ %CLASSGROUP 'Vcl.Controls.TControl' }

{$R *.dfm}

constructor TDataModule1.Create(AOwnet: TComponent);
begin
  inherited;
  getConnection().ConnectionString := getConnectionString();
  getQuery().ConnectionString := getConnectionString();
end;

procedure TDataModule1.executeQuery(query: string);
begin
  getQuery().Active := false;
  getQuery().SQL.Clear;
  getQuery().SQL.Add(query);
  try
    getQuery().prepared := True;
    getQuery().Active := True;
  except
    on E: Exception do
    begin
      // handle connection exceptions
    end;
  end;
end;

function TDataModule1.getConnection(): TADOConnection;
begin
  Result := ADOConnection1;
end;

function TDataModule1.getQuery(): TADOQuery;
begin
  Result := ADOQuery1;
end;

function TDataModule1.getSQLConnectionString: string;
begin
//  Result := TProject.
  Result := 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=magisterka;Data Source=RADEK-PC';//'Provider=SQLOLEDB.1;Password=magisterka;Persist Security Info=True;User ID=magisterka;Initial Catalog=magisterka;Data Source=localhost';
end;

function TDataModule1.getSQLNativeClientConnectionString: string;
begin
//  Result := 'Provider=SQLNCLI10.1;Integrated Security="";Password=magisterka;Persist Security Info=true;User ID=magisterka;Initial Catalog=magisterka;Data Source=localhost;Initial File Name="";Server SPN=""'
end;

function TDataModule1.getConnectionString: string;
begin
  Result := getSQLConnectionString();
end;

end.
